﻿using GalaSoft.MvvmLight.Command;
using KJSyncXP.Access.Context;
using KJSyncXP.Extensions;
using KJSyncXP.Oracle.Context;
using KJSyncXP.Sqlite.Model;
using KJSyncXP.SQLite.Context;
using KJSyncXP.Views;
using KJSyncXP.Views.pop;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Windows;

namespace KJSyncXP.ViewModels
{
    // 检点项目类型模型
    public class CheckItemType
    {
        public string Name { get; set; } // 内部标识名（与属性对应）
        public string DisplayName { get; set; } // 显示名称（界面上的文字）
    }

    public class CheckPointViewModel : BaseViewModel
    {
        private readonly log4net.ILog _logger;
        private readonly AppConfig _appConfig;
        private readonly SqliteDbContext _sqliteCtx;
        private readonly OracleDbContext _oracleCtx;


        #region 声明命令
        public RelayCommand SaveStartWorkCheckPointCommand { get; private set; }
        public RelayCommand AddOptionCommand { get; private set; }
        public RelayCommand<appconfig> RemoveOptionCommand { get; private set; }
        public RelayCommand SaveCheckItemSettingsCommand { get; private set; }
        public RelayCommand RefreshSettingsCommand { get; private set; }
        public RelayCommand ShowStandradCommand { get; private set; }
        public RelayCommand SearchStandradCommand { get; private set; }
        #endregion

        #region 精度检点相关属性
        private string _batchNo;
        public string BatchNo
        {
            get => _batchNo;
            set { _batchNo = value?.Trim(); 
                RaisePropertyChanged("BatchNo"); }
        }

        // 开始时间（检测时间 ≥ 此时间）
        private DateTime? _startDate;
        public DateTime? StartDate
        {
            get => _startDate;
            set { _startDate = value; 
                RaisePropertyChanged("StartDate"); }
        }

        // 结束时间（检测时间 ≤ 此时间）
        private DateTime? _endDate;
        public DateTime? EndDate
        {
            get => _endDate;
            set { _endDate = value; 
                RaisePropertyChanged("EndDate"); }
        }

        // 标准胶料检测结果集合
        private ObservableCollection<SqliteDat200Rh> _standardProductList;
        public ObservableCollection<SqliteDat200Rh> StandardProductList
        {
            get => _standardProductList;
            set {
                _standardProductList = value; 
                RaisePropertyChanged("StandardProductList"); }
        }



        #endregion

        #region 配置相关属性
        // 所有可配置的检点项目类型
        private List<CheckItemType> _checkItemTypes;
        public List<CheckItemType> CheckItemTypes
        {
            get => _checkItemTypes;
            set { _checkItemTypes = value; RaisePropertyChanged("CheckItemTypes"); }
        }

        // 当前选中的检点项目类型
        private CheckItemType _selectedCheckItemType;
        public CheckItemType SelectedCheckItemType
        {
            get => _selectedCheckItemType;
            set
            {
                _selectedCheckItemType = value;
                RaisePropertyChanged("SelectedCheckItemType");
                LoadSelectedCheckItemOptions(); // 加载选中项目的选项
            }
        }

        // 当前选中项目的可选值集合
        private ObservableCollection<appconfig> _selectedCheckItemOptions;
        public ObservableCollection<appconfig> SelectedCheckItemOptions
        {
            get => _selectedCheckItemOptions;
            set { _selectedCheckItemOptions = value; RaisePropertyChanged("SelectedCheckItemOptions"); }
        }
        #endregion

        #region ComboBox选项集合（从配置加载）
        // 设备清洁的选项
        private List<string> _cleanOptions;
        public List<string> CleanOptions
        {
            get => _cleanOptions;
            set { _cleanOptions = value; RaisePropertyChanged("CleanOptions"); }
        }

        // 设备密封效果的选项
        private List<string> _sealEffectOptions;
        public List<string> SealEffectOptions
        {
            get => _sealEffectOptions;
            set { _sealEffectOptions = value; RaisePropertyChanged("SealEffectOptions"); }
        }

        // 仪表性能的选项
        private List<string> _meterPerformanceOptions;
        public List<string> MeterPerformanceOptions
        {
            get => _meterPerformanceOptions;
            set { _meterPerformanceOptions = value; RaisePropertyChanged("MeterPerformanceOptions"); }
        }

        // 设备运转的选项
        private List<string> _deviceOperationOptions;
        public List<string> DeviceOperationOptions
        {
            get => _deviceOperationOptions;
            set { _deviceOperationOptions = value; RaisePropertyChanged("DeviceOperationOptions"); }
        }

        // 夹具/挂钩完好的选项
        private List<string> _fixtureGoodOptions;
        public List<string> FixtureGoodOptions
        {
            get => _fixtureGoodOptions;
            set { _fixtureGoodOptions = value; RaisePropertyChanged("FixtureGoodOptions"); }
        }

        // 基座插销完好的选项
        private List<string> _basePinGoodOptions;
        public List<string> BasePinGoodOptions
        {
            get => _basePinGoodOptions;
            set { _basePinGoodOptions = value; RaisePropertyChanged("BasePinGoodOptions"); }
        }

        // 急停装置完好的选项
        private List<string> _emergencyStopGoodOptions;
        public List<string> EmergencyStopGoodOptions
        {
            get => _emergencyStopGoodOptions;
            set { _emergencyStopGoodOptions = value; RaisePropertyChanged("EmergencyStopGoodOptions"); }
        }

        // 微机运行的选项
        private List<string> _computerRunOptions;
        public List<string> ComputerRunOptions
        {
            get => _computerRunOptions;
            set { _computerRunOptions = value; RaisePropertyChanged("ComputerRunOptions"); }
        }
        #endregion

        #region 头表相关属性
        private string _eqp; // 设备号

        private DateTime? _checkDate; // 检点日期（对应头表RECEIVE_DATE）
        public DateTime? CheckDate
        {
            get => _checkDate;
            set { _checkDate = value; RaisePropertyChanged("CheckDate"); }
        }

        private string _shift; // 班次（对应头表SHIFT）
        public string Shift
        {
            get => _shift;
            set { _shift = value; RaisePropertyChanged("Shift"); }
        }

        private string _userCode; // 作业员工号（对应头表USER_CODE）
        public string UserCode
        {
            get => _userCode;
            set { _userCode = value; RaisePropertyChanged("UserCode"); }
        }

        #endregion

        #region 行表属性（开班检点项）
        // 设备清洁（ComboBox选中值）
        private string _clean;
        public string Clean
        {
            get => _clean;
            set { _clean = value; RaisePropertyChanged("Clean"); }
        }

        // 设备的密封效果（ComboBox选中值）
        private string _sealEffect;
        public string SealEffect
        {
            get => _sealEffect;
            set { _sealEffect = value; RaisePropertyChanged("SealEffect"); }
        }

        // 仪表性能（ComboBox选中值）
        private string _meterPerformance;
        public string MeterPerformance
        {
            get => _meterPerformance;
            set { _meterPerformance = value; RaisePropertyChanged("MeterPerformance"); }
        }

        // 温度(°C)（TextBox数值）
        private decimal? _temperature;
        public decimal? Temperature
        {
            get => _temperature;
            set { _temperature = value; RaisePropertyChanged("Temperature"); }
        }

        // 设备运转（ComboBox选中值）
        private string _deviceOperation;
        public string DeviceOperation
        {
            get => _deviceOperation;
            set { _deviceOperation = value; RaisePropertyChanged("DeviceOperation"); }
        }

        // 夹具、挂钩完好（ComboBox选中值）
        private string _fixtureGood;
        public string FixtureGood
        {
            get => _fixtureGood;
            set { _fixtureGood = value; RaisePropertyChanged("FixtureGood"); }
        }

        // 基座插销完好（ComboBox选中值）
        private string _basePinGood;
        public string BasePinGood
        {
            get => _basePinGood;
            set { _basePinGood = value; RaisePropertyChanged("BasePinGood"); }
        }

        // 压力(MPa)（TextBox数值）
        private decimal? _pressure;
        public decimal? Pressure
        {
            get => _pressure;
            set { _pressure = value; RaisePropertyChanged("Pressure"); }
        }

        // 急停装置完好（ComboBox选中值）
        private string _emergencyStopGood;
        public string EmergencyStopGood
        {
            get => _emergencyStopGood;
            set { _emergencyStopGood = value; RaisePropertyChanged("EmergencyStopGood"); }
        }

        // 微机运行（ComboBox选中值）
        private string _computerRun;
        public string ComputerRun
        {
            get => _computerRun;
            set { _computerRun = value; RaisePropertyChanged("ComputerRun"); }
        }
        #endregion


        // 查询结果集合（绑定到界面DataGrid）
        private List<Sqlite_KJ_EXAMINE_HEADER> _checkPointList;
        public List<Sqlite_KJ_EXAMINE_HEADER> CheckPointList
        {
            get => _checkPointList;
            set { _checkPointList = value; RaisePropertyChanged("CheckPointList"); }
        }



        public CheckPointViewModel(log4net.ILog log, SqliteDbContext sqliteCtx, OracleDbContext oracleCtx, AppConfig appConfig)
        {
            _sqliteCtx = sqliteCtx;
            _oracleCtx = oracleCtx;
            _logger = log;
            _appConfig = appConfig;

            _eqp = _appConfig.DetectionMachineNo;

            // 初始化命令
            SaveStartWorkCheckPointCommand = new RelayCommand(SaveStartWorkCheckPoint);
            AddOptionCommand = new RelayCommand(AddOption);
            RemoveOptionCommand = new RelayCommand<appconfig>(RemoveOption);
            SaveCheckItemSettingsCommand = new RelayCommand(SaveCheckItemSettings);
            RefreshSettingsCommand = new RelayCommand(RefreshSettings);
            ShowStandradCommand = new RelayCommand(ShowStandrad);
            SearchStandradCommand = new RelayCommand(SearchStandrad);


            // 初始化检点项目类型
            InitializeCheckItemTypes();

            // 加载配置的选项
            LoadAllCheckItemOptions();

            // 查询检点数据
            QueryCheckPoint();
        }

        #region 配置相关方法
        // 初始化所有检点项目类型
        private void InitializeCheckItemTypes()
        {
            CheckItemTypes = new List<CheckItemType>
            {
                new CheckItemType { Name = "Clean", DisplayName = "设备清洁" },
                new CheckItemType { Name = "SealEffect", DisplayName = "设备的密封效果" },
                new CheckItemType { Name = "MeterPerformance", DisplayName = "仪表性能" },
                new CheckItemType { Name = "DeviceOperation", DisplayName = "设备运转" },
                new CheckItemType { Name = "FixtureGood", DisplayName = "夹具、挂钩完好" },
                new CheckItemType { Name = "BasePinGood", DisplayName = "基座插销完好" },
                new CheckItemType { Name = "EmergencyStopGood", DisplayName = "急停装置完好" },
                new CheckItemType { Name = "ComputerRun", DisplayName = "微机运行" }
            };

            // 默认选中第一个项目
            if (CheckItemTypes.Any())
                SelectedCheckItemType = CheckItemTypes[0];
        }

        // 加载选中项目的选项
        private void LoadSelectedCheckItemOptions()
        {
            if (SelectedCheckItemType == null)
            {
                SelectedCheckItemOptions = new ObservableCollection<appconfig>();
                return;
            }

            try
            {
                SelectedCheckItemOptions = new ObservableCollection<appconfig>();
                // 从数据库加载配置的选项
                var options = _sqliteCtx.Db.Queryable<appconfig>()
                    .Where(o => o.itemclass == SelectedCheckItemType.Name)
                    .OrderBy(o => o.id)
                    .ToList();
                if (options.Count > 0)
                {
                    SelectedCheckItemOptions = new ObservableCollection<appconfig>(options);
                }        
            }
            catch (Exception ex)
            {
                _logger.Error($"加载{SelectedCheckItemType.DisplayName}选项失败", ex);            
            }
        }

        // 加载所有检点项目的选项到对应的下拉框数据源
        private void LoadAllCheckItemOptions()
        {
            foreach (var itemType in CheckItemTypes)
            {
                try
                {
                    // 从数据库加载选项
                    var options = _sqliteCtx.Db.Queryable<appconfig>()
                        .Where(o => o.itemclass == itemType.Name)
                        .OrderBy(o => o.id)
                        .ToList(o=>o.itemname);

                    // 设置到对应的属性
                    SetOptionListProperty(itemType.Name, options);
                }
                catch (Exception ex)
                {
                    _logger.Error($"加载{itemType.DisplayName}选项失败", ex);
                }
            }
        }

        // 设置选项列表到对应的属性
        private void SetOptionListProperty(string itemName, List<string> options)
        {
            switch (itemName)
            {
                case "Clean":
                    CleanOptions = options;
                    break;
                case "SealEffect":
                    SealEffectOptions = options;
                    break;
                case "MeterPerformance":
                    MeterPerformanceOptions = options;
                    break;
                case "DeviceOperation":
                    DeviceOperationOptions = options;
                    break;
                case "FixtureGood":
                    FixtureGoodOptions = options;
                    break;
                case "BasePinGood":
                    BasePinGoodOptions = options;
                    break;
                case "EmergencyStopGood":
                    EmergencyStopGoodOptions = options;
                    break;
                case "ComputerRun":
                    ComputerRunOptions = options;
                    break;
            }
        }

        #endregion

        #region 命令实现
        
        // 添加新选项
        private void AddOption()
        {
            if (SelectedCheckItemOptions == null)
            {
                SelectedCheckItemOptions = new ObservableCollection<appconfig>();
            }
               
            //当前选中的项目
            var checkType = _selectedCheckItemType.Name;

            SelectedCheckItemOptions.Add(new appconfig
            {
                itemname = "新选项",
                itemvalue ="",
                itemclass = checkType
            });

            // 通知UI刷新
            RaisePropertyChanged("SelectedCheckItemOptions");
        }

        // 删除选项
        private void RemoveOption(appconfig option)
        {
            if (SelectedCheckItemOptions != null && option != null)
            {
                SelectedCheckItemOptions.Remove(option);
                // 通知UI刷新
                RaisePropertyChanged("SelectedCheckItemOptions");
            }
        }

        // 保存配置
        private void SaveCheckItemSettings()
        {
            if (SelectedCheckItemType == null || SelectedCheckItemOptions == null || !SelectedCheckItemOptions.Any())
            {
                return;
            }
                
            try
            {
                _sqliteCtx.Db.Ado.Transaction(() =>
                {
                    // 删除该项目的所有选项
                    int deletedCount = _sqliteCtx.Db.Delete<appconfig>()
                                      .Where(o => o.itemclass == SelectedCheckItemType.Name)  
                                      .ExecuteAffrows();
                    
                    // 插入的新选项
                    var currentTime = DateTime.Now;
                    foreach (var option in SelectedCheckItemOptions)
                    {
                        option.createdate = currentTime;
                    }
                    var optionsToSave = SelectedCheckItemOptions
                        .Where(o => !string.IsNullOrWhiteSpace(o.itemname) && !string.IsNullOrWhiteSpace(o.itemvalue)) // 过滤空选项
                        .ToList();

                    // 批量插入新选项
                    if (optionsToSave.Any())
                    {
                        int insertedCount = _sqliteCtx.Db.Insert<appconfig>(optionsToSave).ExecuteAffrows();
                    }
                });

                // 重新加载所有选项，使修改生效
                LoadAllCheckItemOptions();

                // 显示成功提示
                var notification = new CustomNotificationWindow
                {
                    NotificationTitle = "检点设置提示",
                    NotificationContent = "检点项目配置成功"
                };
                notification.ShowDialog();
            }
            catch (Exception ex)
            {
                _logger.Error($"保存{SelectedCheckItemType.DisplayName}配置失败", ex);
            }
        }


        // 刷新配置
        private void RefreshSettings()
        {
            LoadAllCheckItemOptions();
            LoadSelectedCheckItemOptions();
        }


        public void ShowStandrad()
        {
            StandardSelectWindow standardSelectWindow = new StandardSelectWindow();
            standardSelectWindow.ShowDialog();
        }



        #endregion


        public void SearchStandrad()
        {
           
            try
            {
                var productList = _sqliteCtx.Db.Queryable<StandardProduct>().ToList();

                // 校验标准胶料集合否加载成功
                if (productList == null || productList.Count == 0)
                {
                    MessageBox.Show("未加载到标准胶料数据，请先打开「标准胶料」窗口！", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                // 获取所有标准胶料号
                var validProductNumbers = productList.Select(p => p.ProductNumber).ToList();

                // 构建数据库查询
                var query = _sqliteCtx.Db.Queryable<SqliteDat200Rh>();

                query = query.Where(m => validProductNumbers.Contains(m.F10));

                if (!string.IsNullOrEmpty(BatchNo))
                {
                    query = query.Where(m => m.F14 == BatchNo);
                }

                if (StartDate.HasValue)
                {
                    query = query.Where(m => m.CREATE_DATE >= StartDate);
                }

                if (EndDate.HasValue)
                {
                    query = query.Where(m => m.CREATE_DATE <= EndDate);
                }
                
                var filteredResult = query.ToList();

                StandardProductList = new ObservableCollection<SqliteDat200Rh>(filteredResult);

                //MessageBox.Show($"检索完成，共找到 {FilteredProductList.Count} 条符合条件的记录", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                _logger.Error("胶料检索失败", ex);
                MessageBox.Show("检索失败，请检查数据库连接或筛选条件！", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                StandardProductList.Clear();
            }

        }


        public void SaveStartWorkCheckPoint()
        {
            _sqliteCtx.Db.Ado.Transaction(() => {
                var headdata = new Sqlite_KJ_EXAMINE_HEADER()
                {
                    CREATION_DATE = DateTime.Now,
                    EQP = _eqp,
                    EXAMINE_PROJECT = "开班检点",
                    RECEIVE_FLAG = "PENDING",
                    SHIFT = Shift,
                    USER_CODE = UserCode,
                };
                var headid = _sqliteCtx.Db.Insert<Sqlite_KJ_EXAMINE_HEADER>(headdata).ExecuteIdentity();


                // 构建行表数据列表（每个检点项对应一行）
                List<Sqlite_KJ_EXAMINE_LINE> lineDatas = new List<Sqlite_KJ_EXAMINE_LINE>
                    {
                        // 设备清洁
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="设备清洁",
                            EXAMINE_VALUE =Clean,
                            RECEIVE_FLAG="PENDING"
                        },
                        // 设备的密封效果
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="设备的密封效果",
                            EXAMINE_VALUE =SealEffect,
                            RECEIVE_FLAG="PENDING",
                        },
                        // 仪表性能
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="仪表性能",
                            EXAMINE_VALUE =MeterPerformance,
                            RECEIVE_FLAG="PENDING",
                        },
                        // 温度(°C)（含数值型结果EXAMINE_VALUE）
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="温度(°C)",
                            EXAMINE_VALUE =Temperature.Value.ToString("F1"),
                            RECEIVE_FLAG="PENDING",
                        },
                        // 设备运转
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="设备运转",
                            EXAMINE_VALUE =DeviceOperation,
                            RECEIVE_FLAG="PENDING",
                        },
                        // 夹具、挂钩完好
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="夹具、挂钩完好",
                            EXAMINE_VALUE =FixtureGood,
                            RECEIVE_FLAG="PENDING",
                        },
                        // 基座插销完好
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="基座插销完好",
                            EXAMINE_VALUE =BasePinGood,
                            RECEIVE_FLAG="PENDING",
                        },
                        // 压力(MPa)（含数值型结果EXAMINE_VALUE）
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="压力(MPa)",
                            EXAMINE_VALUE =Pressure.Value.ToString("F2"),
                            RECEIVE_FLAG="PENDING",
                        },
                        // 急停装置完好
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="急停装置完好",
                            EXAMINE_VALUE = EmergencyStopGood,
                            RECEIVE_FLAG="PENDING",
                        },
                        // 微机运行
                        new Sqlite_KJ_EXAMINE_LINE()
                        {
                            CREATION_DATE = DateTime.Now,
                            EXAMINE_ID = headid.ToString(),
                            EXAMINE_NAME ="微机运行",
                            EXAMINE_VALUE = ComputerRun,
                            RECEIVE_FLAG="PENDING",
                        }
                    };

                // 批量插入行表数据
                int lineCount = _sqliteCtx.Db.Insert<Sqlite_KJ_EXAMINE_LINE>(lineDatas).ExecuteAffrows();

            });
            QueryCheckPoint();
        }

        /// <summary>
        /// 查询检点数据（核心：头表+行表关联，行转列）
        /// </summary>
        public void QueryCheckPoint()
        {
            try
            {
                // 查询“检点头表”
                var headers = _sqliteCtx.Db.Queryable<Sqlite_KJ_EXAMINE_HEADER>()
                    .Where(h => h.EQP == _eqp) // 按当前设备号过滤
                    .OrderByDescending(h => h.CREATION_DATE) // 按创建时间倒序
                    .ToList();

                var resultList = new List<Sqlite_KJ_EXAMINE_HEADER>();
                int serialNumber = 1; // 序号从1开始

                // 遍历头表，逐个关联行表并组装DTO
                foreach (var header in headers)
                {
                    var dto = new Sqlite_KJ_EXAMINE_HEADER
                    {
                        Index = serialNumber++,
                        USER_CODE = header.USER_CODE,
                        EQP = header.EQP,
                        SHIFT = header.SHIFT,
                        CREATION_DATE = header.CREATION_DATE // 假设CREATION_DATE为检点日期
                    };

                    // 查询当前头表对应的“检点行表”
                    var lines = _sqliteCtx.Db.Queryable<Sqlite_KJ_EXAMINE_LINE>()
                        .Where(l => l.EXAMINE_ID == header.LJ_ID.ToString()) // 头表LJ_ID对应行表EXAMINE_ID
                        .ToList();

                    // 行转列：将不同EXAMINE_NAME的行，映射到DTO的列
                    foreach (var line in lines)
                    {
                        switch (line.EXAMINE_NAME)
                        {
                            case "设备清洁":
                                dto.Clean = line.EXAMINE_VALUE;
                                break;
                            case "设备的密封效果":
                                dto.SealEffect = line.EXAMINE_VALUE;
                                break;
                            case "仪表性能":
                                dto.MeterPerformance = line.EXAMINE_VALUE;
                                break;
                            case "温度(°C)":
                                if (decimal.TryParse(line.EXAMINE_VALUE, out decimal temp))
                                {
                                    dto.Temperature = temp;
                                }
                                break;
                            case "设备运转":
                                dto.DeviceOperation = line.EXAMINE_VALUE;
                                break;
                            case "夹具、挂钩完好":
                                dto.FixtureGood = line.EXAMINE_VALUE;
                                break;
                            case "基座插销完好":
                                dto.BasePinGood = line.EXAMINE_VALUE;
                                break;
                            case "压力(MPa)":
                                if (decimal.TryParse(line.EXAMINE_VALUE, out decimal press))
                                {
                                    dto.Pressure = press;
                                }
                                break;
                            case "急停装置完好":
                                dto.EmergencyStopGood = line.EXAMINE_VALUE;
                                break;
                            case "微机运行":
                                dto.ComputerRun = line.EXAMINE_VALUE;
                                break;
                        }
                    }

                    resultList.Add(dto);
                }

                // 绑定结果到UI
                CheckPointList = resultList;
            }
            catch (Exception ex)
            {
                _logger.Error("查询检点数据失败", ex);
            }
        }
    }
}
